import {Card, Col, Divider, Row, Statistic, Steps} from "antd";
import React from "react";
import {SisternodeOutlined} from "@ant-design/icons";
import "./index.css"
import {GetGoroutineNum} from "../../services/laike/system";

function DashBoard() {

    const { Step } = Steps;


    let [goroutineNum, setGoroutineNum] = React.useState(0)
    let timer = 0

    React.useEffect(()=>{
        updateGoroutineNum()

        timer = setInterval(()=>{
            updateGoroutineNum()
        },3000)

        return ()=>{
            clearInterval(timer)
        }
    })

    // 更新协程数量
    const updateGoroutineNum = ()=>{
        GetGoroutineNum().then((res)=>{
            setGoroutineNum(res.data.Count)
        })
    }

    return (
        <>
            <Steps current={1}>
                <Step title="构思" description="吃饱了乱想" />
                <Step title="实现" subTitle="EveryTime" description="生命在于折腾" />
                <Step title="完成" subTitle="LoooooongTime" description="是不可能的" />
            </Steps>

            <Divider orientation="left">系统态</Divider>
            <div className="system-info">
                <Row gutter={16}>
                    <Col span={4}>
                        <Card >
                            <Statistic
                                title="协程数"
                                value={goroutineNum}
                                valueStyle={{color: '#3f8600'}}
                                prefix={<SisternodeOutlined/>}
                            />
                        </Card>
                    </Col>
                </Row>
            </div>

            <SoftWareVersion/>
        </>
    )
}

function SoftWareVersion() {
    return (
        <>
            <Divider />
            <Row gutter={16}>
                <Col span={6}>
                    <Statistic title="当前版本" value={"V 0.1.5"}/>
                </Col>
                <Col span={12}>
                    <Statistic title="最后更新日期" value={"2022-01-28"}/>
                </Col>
            </Row>
        </>
    )
}

export default DashBoard